/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.thoughtbot.expandablerecyclerview.sample;

import com.thoughtbot.expandablerecyclerview.sample.expand.ExpandAbility;
import com.thoughtbot.expandablerecyclerview.sample.multicheck.MultiCheckAbility;
import com.thoughtbot.expandablerecyclerview.sample.multitype.MultiTypeAbility;
import com.thoughtbot.expandablerecyclerview.sample.multitypeandcheck.MultiTypeAndCheckAbility;
import com.thoughtbot.expandablerecyclerview.sample.singlecheck.SingleCheckAbility;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.utils.Color;
import ohos.agp.window.service.WindowManager;

/**
 * MainAbility
 *
 * @since 2021-07-23
 */
public class MainAbility extends Ability implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_main);

        // 设置状态栏颜色
        WindowManager.getInstance().getTopWindow().get().setStatusBarColor(new Color(0xFFD32E2E).getValue());
        initView();
    }

    private void initView() {
        Button expandButton = (Button)findComponentById(ResourceTable.Id_expand_button);
        Button multiCheckButton = (Button)findComponentById(ResourceTable.Id_multi_check_button);
        Button singleCheckButton = (Button)findComponentById(ResourceTable.Id_single_check_button);
        Button mixedTypeButton = (Button)findComponentById(ResourceTable.Id_mixed_type_button);
        Button mixedTypeCheckButton = (Button) findComponentById(ResourceTable.Id_mixed_type_check_button);

        expandButton.setClickable(true);
        expandButton.setClickedListener(this);
        multiCheckButton.setClickable(true);
        multiCheckButton.setClickedListener(this);
        singleCheckButton.setClickable(true);
        singleCheckButton.setClickedListener(this);
        mixedTypeButton.setClickable(true);
        mixedTypeButton.setClickedListener(this);
        mixedTypeCheckButton.setClickable(true);
        mixedTypeCheckButton.setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_expand_button:
                jumpAbility(ExpandAbility.class);
                break;
            case ResourceTable.Id_multi_check_button:
                jumpAbility(MultiCheckAbility.class);
                break;
            case ResourceTable.Id_single_check_button:
                jumpAbility(SingleCheckAbility.class);
                break;
            case ResourceTable.Id_mixed_type_button:
                jumpAbility(MultiTypeAbility.class);
                break;
            case ResourceTable.Id_mixed_type_check_button:
                jumpAbility(MultiTypeAndCheckAbility.class);
                break;
            default:
                break;
        }
    }

    /**
     * 跳转页面
     *
     * @param clazz clazz
     */
    private void jumpAbility(Class clazz) {
        Intent intent = new Intent();
        intent.setOperation(new Intent.OperationBuilder()
            .withBundleName(getContext().getBundleName())
            .withAbilityName(clazz)
            .build());
        startAbility(intent);
    }
}

